package models;

import java.util.*;

import javax.persistence.*;

import play.db.jpa.*;

/**
 * 
 * @author emam
 * @params user to have ithe author name
 * @params title to add the titel of the topic on the DB
 * @params content to add the describtion of the topic on the DB
 * @params ideas to have ideas under topics
 */
/* this class task is to create topic */

@Entity
public class Topic extends Model {

	public String title;
	public Date pDate;
	@ManyToMany
	public List<Tag> tag;
	@Lob
	public String content;
	@ManyToOne
	public User user;
	@OneToMany
	public List<Idea> ideas;
	public Date lastactivity;

    public int views;
	public boolean isLocked;
    @ManyToMany
	  public List<User> toBeNotified;


	/**
	 * 
	 * @author emam
	 * @params user to have ithe author name
	 * @params title to add the titel of the topic on the DB
	 * @params content to add the describtion of the topic on the DB
	 */
	/* this is the constructor of the class */
	public Topic(User author, String title, String content) {
		toBeNotified = new ArrayList<User>();
		this.user = author;
		this.title = title;
		this.content = content;
		this.pDate = new Date();
		lastactivity=this.pDate;
	}

	public void addTag(Tag tag) {
		this.tag.add(tag);
	}

	/**
	 * @author Khalid Osama
	 * @param user to be added to the list of followers.
	 * this method adds the new user to the list of followers.
	 */
	public void addFollowers(User user) {
			toBeNotified.add(user);
	}
	
	/**
	 * @author Khalid Osama
	 * @param user to check whether following or not.
	 * this method checks whether the user is following or not.
	 * @return true if following, false if not.
	 */
	public boolean isFollowing(User user){
		if (toBeNotified.contains(user)) {
			return true;
		} else {
			return false;
		}
	}
}